package jk.fox.exchange.client;

import jk.fox.common.RpcDict;
import jk.fox.node.NodeStatusListener;

import java.net.InetSocketAddress;
import java.net.URI;

/**
 * @author cuichao
 * @Description: jk.fox.serverExchange.ClientExchange
 * @Date: create in 2020/3/28 13:32
 */
public interface ClientExchange<T> {
    /**
     * 连续远程服务
     * @param address
     * @return
     * @throws Exception
     */
    T connection(InetSocketAddress address) throws Exception;

    /**
     * 执行Rpc服务
     * @param uri
     * @param parameters
     * @param parameterTypes
     * @return
     * @throws Exception
     */
    Object execute(URI uri, Object[] parameters,String[] parameterTypes) throws Exception;

    /**
     * 规定时间执行Rpc服务
     * @param uri
     * @param parameters
     * @param parameterTypes
     * @param timeout
     * @return
     * @throws Exception
     */
    Object execute(URI uri, Object[] parameters,String[] parameterTypes, long timeout) throws Exception;

    /**
     * 判断该连接是否存活
     * @param t
     * @return
     */
    boolean isActive(T t);
    /**
     * 添加Server状态监听
     * @param listener
     */
    void addServerStatusListener(NodeStatusListener listener);
    /**
     * 发布事件监听
     * @param address
     * @param status
     * @param e
     */
    void publishServerStatus(String address, RpcDict.NodeStatus status, Exception e);
    
}
